package cc.ilzy.mall.product.controller;

import cc.ilzy.mall.api.controller.ICartController;
import cc.ilzy.mall.model.request.CartItemRequest;
import cc.ilzy.mall.model.vo.CartVO;
import cc.ilzy.mall.product.service.ICartService;
import cc.ilzy.mall.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CartController implements ICartController {
    @Autowired
    private ICartService cartService;

    @Override
    public ApiResponse<Void> addCart(CartItemRequest cartItemRequest) {
        cartService.addToCart(cartItemRequest);
        return ApiResponse.success();
    }

    @Override
    public ApiResponse<Void> clearCart() {
        cartService.clear();
        return ApiResponse.success();
    }

    @Override
    public ApiResponse<CartVO> getMyCart() {
        CartVO cartVO = cartService.getMyCart();
        return ApiResponse.success(cartVO);
    }

    @Override
    public ApiResponse<Void> deleteCart(Long productId) {
        cartService.deleteItem(productId);
        return ApiResponse.success();
    }

    @Override
    public ApiResponse<Void> changeCartItemNum(CartItemRequest cartItemRequest) {
        cartService.changeItemNum(cartItemRequest);
        return ApiResponse.success();
    }
}
